#include<iostream>
using namespace std;

class Solution
{
public:

	int bitSum(int n)
	{
		int sum = 0;
		while (n)
		{
			int ret = n % 10;
			sum += ret * ret;
			n /= 10;
		}
	}
	bool isHappy(int n)
	{
		int slow = n, fast = bitSum(n);
		while (slow != fast)
		{
			slow = bitSum(slow);
			fast = bitSum(bitSum(fast));
		}
		return slow == 1;
	}
};
